package com.hqm.common.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author : fengSir
 * @date : 16:08 2021/11/12
 */
//@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return com.hqm.common.exception.Result.error().message(e.getMessage());
    }

    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public Result error(CustomException e){
        log.error(e.getMsg());
        return com.hqm.common.exception.Result.error().code(e.getCode()).message(e.getMsg());
    }
}
